<?php

// 完善投资喜好
// PUT member.like.complete

namespace app\api\resource\member\like;
use think\Db;
use think\Loader;
use think\Session;

class Complete
{
    // 方法
    public $_method = ['PUT'];
    // 前置
    public $_pre    = ['login','isTzz'];
    // 描述
    public $_description = '完善投资喜好';
    // 参数
    public $_param  = [
        'round'       => '投资轮次,JsonArray',
        'industry'    => '投资行业,JsonArray',
        'city'        => '关注城市,JsonArray',
        'begin_money' => '投资启端金额(万)',
        'end_money'   => '投资末端金额(万)',
    ];
    // 返回
    public $_return = [
        201 => '完善成功',
        422 => '请求参数不合法',
        500 => '服务器错误',
    ];

    public function run(&$request)
    {
        $params['round']       = $request->put('round/s','','trim');
        $params['industry']    = $request->put('industry/s','','trim');
        $params['city']        = $request->put('city/s','','trim');
        $params['begin_money'] = $request->put('begin_money/d',0,'abs');
        $params['end_money']   = $request->put('end_money/d',0,'abs');

        $validate = Loader::validate('MemberLike');
        if ( !$validate->scene('complete')->check($params) ) {
            $errMsg = $validate->getError();
            return [422,$errMsg];
        }

        $memberId = Session::get('member.id');

        $num = Db::name('member_like')->where('member_id',$memberId)->update($params);
        return ($num >= 0) ? [ 201,[] ] : 500;
    }
}